package com.seaboxdata.controller;

import com.seaboxdata.entity.YqfkCommunityAddressVo;
import com.seaboxdata.service.SecurityService;
import com.seaboxdata.service.YqfkService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author
 * @create 2021-04-12 14:40
 **/
@RestController
@EnableAutoConfiguration
@RequestMapping("/yqfk")
public class YqfkController {

    @Autowired
    private YqfkService yqfkService;

    @Autowired
    private SecurityService securityService;

    @RequestMapping("/getCommunityAddressById")
    public Map<String, Object> getRkxxById(@RequestBody YqfkCommunityAddressVo yqfkCommunityAddressVo) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        int retCode = 0;
        String retMessage = "SUCCESS";
        if (yqfkCommunityAddressVo == null || StringUtils.isEmpty(yqfkCommunityAddressVo.getAccessKey())
                || StringUtils.isEmpty(yqfkCommunityAddressVo.getSelectKey())) {
            retCode = 1;
            retMessage = "selectKey and accessKey not allowed null";
            resultMap.put("retCode", retCode);
            resultMap.put("retMessage", retMessage);
            resultMap.put("data", null);
            return resultMap;
        }
        if (!securityService.isSecurity(yqfkCommunityAddressVo.getSelectKey(), yqfkCommunityAddressVo.getAccessKey())) {
            retCode = 1;
            retMessage = "invalid selectKey or accessKey";
            resultMap.put("retCode", retCode);
            resultMap.put("retMessage", retMessage);
            resultMap.put("data", null);
            return resultMap;
        }
        resultMap.put("retCode", retCode);
        resultMap.put("retMessage", retMessage);
        resultMap.put("data", yqfkService.getCommunityAddressById(yqfkCommunityAddressVo));
        return resultMap;
    }
}
